package com.ruoyi.web.controller.app;

import java.util.HashMap;
import java.util.List;
import java.util.Map;
import javax.servlet.http.HttpServletResponse;

import com.ruoyi.system.domain.TAccountRecords;
import com.ruoyi.system.domain.TConsumeRecords;
import com.ruoyi.system.mapper.TRefusalRecordsMapper;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.TRefusalRecords;
import com.ruoyi.system.service.ITRefusalRecordsService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 拒付Controller
 * 
 * @author ruoyi
 * @date 2024-07-02
 */
@RestController
@RequestMapping("/system/refusalRecords")
public class TRefusalRecordsController extends BaseController
{
    @Autowired
    private ITRefusalRecordsService tRefusalRecordsService;
    @Autowired
    private TRefusalRecordsMapper tRefusalRecordsMapper;

    /**
     * 管理专用
     */
    @PostMapping("/allSummary")
    public AjaxResult allSummary(@RequestBody TRefusalRecords tRefusalRecords){
        return AjaxResult.success(tRefusalRecordsService.allSummary(tRefusalRecords));
    }

    /**
     * 投手专用
     */
    @PostMapping("/mySummary")
    public AjaxResult mySummary(@RequestBody TRefusalRecords tRefusalRecords){
        tRefusalRecords.setUid(getUserId());
        return AjaxResult.success(tRefusalRecordsService.mySummary(tRefusalRecords));
    }

    /**
     * 合计
     */
    @PostMapping("/sum")
    public AjaxResult sum(@RequestBody TRefusalRecords tRefusalRecords){
        Map<String,Object> map = new HashMap<>();
        map.put("amount",tRefusalRecordsMapper.amountByAll(tRefusalRecords));
        return AjaxResult.success(map);
    }
    /**
     * 查询拒付列表
     */
    @PreAuthorize("@ss.hasPermi('system:refusalRecords:list')")
    @GetMapping("/list")
    public TableDataInfo list(TRefusalRecords tRefusalRecords)
    {
        startPage();
        tRefusalRecords.setUid(getUserId());
        List<TRefusalRecords> list = tRefusalRecordsService.selectTRefusalRecordsList(tRefusalRecords);
        return getDataTable(list);
    }

    @PreAuthorize("@ss.hasPermi('system:refusalData:list')")
    @GetMapping("/adminList")
    public TableDataInfo adminList(TRefusalRecords tRefusalRecords)
    {
        startPage();
        List<TRefusalRecords> list = tRefusalRecordsService.selectTRefusalRecordsList(tRefusalRecords);
        return getDataTable(list);
    }

    /**
     * 导出拒付列表
     */
    @PreAuthorize("@ss.hasPermi('system:refusalRecords:export')")
    @Log(title = "拒付", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, TRefusalRecords tRefusalRecords)
    {
        List<TRefusalRecords> list = tRefusalRecordsService.selectTRefusalRecordsList(tRefusalRecords);
        ExcelUtil<TRefusalRecords> util = new ExcelUtil<TRefusalRecords>(TRefusalRecords.class);
        util.exportExcel(response, list, "拒付数据");
    }

    /**
     * 获取拒付详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:refusalRecords:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(tRefusalRecordsService.selectTRefusalRecordsById(id));
    }

    /**
     * 新增拒付
     */
    @PreAuthorize("@ss.hasPermi('system:refusalRecords:add')")
    @Log(title = "拒付", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody TRefusalRecords tRefusalRecords)
    {
        tRefusalRecords.setUid(getUserId());
        return toAjax(tRefusalRecordsService.insertTRefusalRecords(tRefusalRecords));
    }

    /**
     * 修改拒付
     */
    @PreAuthorize("@ss.hasPermi('system:refusalRecords:edit')")
    @Log(title = "拒付", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody TRefusalRecords tRefusalRecords)
    {
        return toAjax(tRefusalRecordsService.updateTRefusalRecords(tRefusalRecords));
    }

    /**
     * 删除拒付
     */
    @PreAuthorize("@ss.hasPermi('system:refusalRecords:remove')")
    @Log(title = "拒付", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(tRefusalRecordsService.deleteTRefusalRecordsByIds(ids));
    }

    /**
     * 一键同步
     */
    @PreAuthorize("@ss.hasPermi('system:refusalRecords:syn')")
    @Log(title = "拒付", businessType = BusinessType.UPDATE)
    @PostMapping("/syn")
    public AjaxResult syn(){
        tRefusalRecordsService.syn();
        return AjaxResult.success();
    }
}
